home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Workbench Add-On
/
Workbench Add-On - Volume 1.iso
/
Dev
/
Oberon
/
source
/
FPE
/
Data.mod
< prev
next >
Wrap
Text File
|
1995-06-29
|
17KB
|
657 lines
(*************************************************************************
$RCSfile: Data.mod $
Description: Global data declarations and operations for the FPE utility
program.
Created by: fjc (Frank Copeland)
$Revision: 1.12 $
$Author: fjc $
$Date: 1995/05/08 16:41:15 $
Copyright © 1993-1995, Frank Copeland.
This file is part of FPE.
See FPE.doc for conditions of use and distribution.
Log entries are at the end of the file.
*************************************************************************)
<* STANDARD- *> <* INITIALISE- *> <* MAIN- *> <*$ NilChk- *>
MODULE Data;
IMPORT
SYS := SYSTEM, Kernel, e := Exec, es := ExecSupport, eu := ExecUtil,
u := Utility, d := Dos, du := DosUtil, is := IntuiSup,
isu := IntuiSupUtil, str := Strings, str2 := Strings2;
CONST
NumFiles * = 4;
NumTools * = 12;
FileChars * = 32;
ExtensionChars * = 8;
PathChars * = 254;
ButtonChars * = 10;
ConsoleChars * = 60;
Notice = "FPE Notice";
FPEPF = 046504500H;
PrefsVersion = 1;
TYPE
FileName * = ARRAY FileChars + 1 OF CHAR;
Path * = ARRAY PathChars + 1 OF CHAR;
Extension * = ARRAY ExtensionChars + 1 OF CHAR;
ModuleNodePtr * = POINTER [2] TO ModuleNode;
ModuleNode = RECORD [2] (e.Node)
modName : FileName;
END; (* ModuleNode *)
ButtonText = ARRAY ButtonChars + 1 OF CHAR;
Console = ARRAY ConsoleChars + 1 OF CHAR;
ToolInfo * = RECORD
title * : ButtonText;
command *,
arguments * : Path;
isActive *,
hasConsole * : BOOLEAN;
console * : Console;
stack * : LONGINT;
END; (* ToolInfo *)
FileSet = SYS.BYTESET;
ToolsArray = ARRAY NumTools OF ToolInfo;
SkeletonsArray = ARRAY NumFiles OF Path;
ExtensionsArray = ARRAY NumFiles OF Extension;
VAR
currentPath * : Path;
programName * : FileName;
moduleList * : e.List;
currentModule * : ModuleNodePtr;
currentModuleNo * : LONGINT;
currentFiles * : FileSet;
tools * : ToolsArray;
extensions * : ExtensionsArray;
currentDir * : d.FileLockPtr;
DefSetupPath : Path;
AltSetupPath : Path;
(*skeletons : SkeletonsArray;*)
(*icon : Path;*)
(*------------------------------------*)
PROCEDURE ChangeDirectory * ( newDir : ARRAY OF CHAR );
VAR result : LONGINT; newLock, oldDir : d.FileLockPtr;
<*$CopyArrays-*>
BEGIN (* ChangeDirectory *)
newLock := d.Lock (newDir, d.sharedLock);
IF newLock # NIL THEN
oldDir := d.CurrentDir (newLock);
d.UnLock (currentDir); currentDir := newLock;
ASSERT (d.NameFromLock (currentDir, currentPath, PathChars))
ELSE
isu.DoNotice (NIL, SYS.ADR (Notice), "Could not lock new directory");
END
END ChangeDirectory;
(*------------------------------------*)
PROCEDURE MakeModule * ( module : ARRAY OF CHAR );
VAR
newNode : ModuleNodePtr;
<*$CopyArrays-*>
BEGIN (* MakeModule *)
NEW (newNode); ASSERT (newNode # NIL, 137);
newNode.name := SYS.ADR(newNode.modName);
COPY (module, newNode.modName);
e.AddTail (moduleList, newNode);
IF currentModule = NIL THEN
currentModule := SYS.VAL (ModuleNodePtr, moduleList.head);
currentModuleNo := 0
END
END MakeModule;
(*------------------------------------*)
PROCEDURE RemoveModule * ();
VAR module : ModuleNodePtr;
BEGIN (* RemoveModule *)
IF currentModule # NIL THEN
module := currentModule;
IF module.succ.succ = NIL THEN
currentModule := SYS.VAL (ModuleNodePtr, moduleList.head);
currentModuleNo := 0
ELSE
currentModule := SYS.VAL (ModuleNodePtr, module.succ);
END;
e.Remove (module);
SYS.DISPOSE (module)
END
END RemoveModule;
(*------------------------------------*)
PROCEDURE ScanModules * () : BOOLEAN;
VAR
module : FileName;
fileInfo : d.FileInfoBlockPtr;
file, fileLength, dotPos : INTEGER;
extLength : ARRAY NumFiles OF INTEGER;
extension : Extension;
result : BOOLEAN;
thisModule : e.MinNodePtr;
BEGIN (* ScanModules *)
result := TRUE;
NEW (fileInfo); ASSERT (fileInfo # NIL, 137);
thisModule := SYS.VAL (e.MinNodePtr, e.RemHead (moduleList));
WHILE thisModule # NIL DO
SYS.DISPOSE (thisModule);
thisModule := SYS.VAL (e.MinNodePtr, e.RemHead (moduleList));
END;
currentModule := NIL; currentModuleNo := 0;
file := 0;
WHILE file < NumFiles DO
extLength [file] := str.Length (extensions [file]); INC (file)
END;
IF d.Examine (currentDir, fileInfo^) THEN
WHILE d.ExNext (currentDir, fileInfo^) DO
IF fileInfo.dirEntryType < 0 THEN
file := 0;
LOOP
IF file >= NumFiles THEN EXIT; END;
fileLength := str.Length (fileInfo.fileName);
dotPos := fileLength - extLength [file] - 1;
IF (dotPos >= 0) & (fileInfo.fileName [dotPos] = ".") THEN
str.Extract
(fileInfo.fileName, dotPos + 1, extLength [file], extension);
IF str2.CompareCAP (extension, extensions [file]) = 0 THEN
str.Extract (fileInfo.fileName, 0, dotPos, module);
IF e.FindName (moduleList, module) = NIL THEN
MakeModule (module);
END;
EXIT
END;
END;
INC (file)
END; (* LOOP *)
END; (* IF *)
END; (* WHILE *)
ELSE
result := FALSE
END;
SYS.DISPOSE (fileInfo);
RETURN result;
END ScanModules;
(*------------------------------------*)
PROCEDURE LoadProgram * ( program : ARRAY OF CHAR ) : BOOLEAN;
VAR
progFile : is.FileDataPtr;
prgName : Path;
module : FileName;
thisModule : e.MinNodePtr;
fileResult : INTEGER;
result : BOOLEAN;
<*$CopyArrays-*>
BEGIN (* LoadProgram *)
result := TRUE;
thisModule := SYS.VAL (e.MinNodePtr, e.RemHead (moduleList));
WHILE thisModule # NIL DO
SYS.DISPOSE (thisModule);
thisModule := SYS.VAL (e.MinNodePtr, e.RemHead (moduleList))
END;
currentModule := NIL; currentModuleNo := 0;
COPY (program, programName);
COPY (program, prgName);
str.Append (".prg", prgName);
progFile :=
is.OpenTextFile
( prgName, 1000, 100, {is.tfTrimLine .. is.tfSkipEmptyLines});
IF progFile # NIL THEN
module := "";
LOOP
fileResult := is.ReadTextLine (progFile);
IF fileResult # is.normal THEN EXIT END;
COPY (progFile.line^, module);
IF module [0] # 0X THEN MakeModule (module) END
END;
is.CloseTextFile (progFile)
ELSE
result := FALSE
END;
RETURN result;
END LoadProgram;
(*------------------------------------*)
PROCEDURE SaveProgram * () : BOOLEAN;
VAR
progFile : d.FileHandlePtr;
prgName : Path;
module : ModuleNodePtr;
result : BOOLEAN;
PROCEDURE WriteLine ( string : ARRAY OF CHAR );
VAR ch : CHAR;
fileResult : LONGINT;
<*$CopyArrays-*>
BEGIN (* WriteLine *)
fileResult := d.Write (progFile, string, str.Length (string));
ch := "\n"; fileResult := d.Write (progFile, ch, 1);
END WriteLine;
BEGIN (* SaveProgram *)
result := TRUE;
COPY (programName, prgName);
str.Append (".prg", prgName);
progFile := d.Open (prgName, d.newFile);
IF progFile # NIL THEN
module := SYS.VAL (ModuleNodePtr, eu.GetHead (moduleList));
WHILE module # NIL DO
WriteLine (module.modName);
module := SYS.VAL (ModuleNodePtr, eu.GetSucc (module))
END;
d.OldClose( progFile );
ELSE
result := FALSE;
END;
RETURN result;
END SaveProgram;
(*------------------------------------*)
PROCEDURE LoadSetup * ( setupDir, setupFile : ARRAY OF CHAR );
VAR
setupPath : Path; pf : d.FileHandlePtr; tag : LONGINT;
i, ver : INTEGER; c : CHAR;
PROCEDURE Read ( fh : d.FileHandlePtr; VAR x : SYS.BYTE );
VAR i : LONGINT;
BEGIN (* Read *)
i := d.FGetC (fh); x := CHR (i)
END Read;
PROCEDURE ReadBytes
( fh : d.FileHandlePtr; VAR x : ARRAY OF SYS.BYTE; n : LONGINT );
VAR i : LONGINT;
BEGIN (* ReadBytes *)
i := d.FRead (fh, x, 1, n)
END ReadBytes;
PROCEDURE ReadString ( fh : d.FileHandlePtr; VAR x : ARRAY OF CHAR );
VAR ch : CHAR; i : INTEGER;
BEGIN (* ReadString *)
i := 0;
REPEAT
Read (fh, ch); x [i] := ch; INC (i)
UNTIL ch = 0X
END ReadString;
PROCEDURE ReadBool ( fh : d.FileHandlePtr; VAR x : BOOLEAN );
VAR i : SHORTINT;
BEGIN (* ReadBool *)
Read (fh, i); x := (i # 0)
END ReadBool;
<*$CopyArrays-*>
BEGIN (* LoadSetup *)
COPY (setupDir, setupPath);
ASSERT (d.AddPart (setupPath, setupFile, PathChars));
pf := d.Open (setupPath, d.oldFile);
IF pf # NIL THEN
ReadBytes (pf, tag, 4);
IF tag = FPEPF THEN
Read (pf, c); ver := ORD (c);
IF ver >= 1 THEN
FOR i := 0 TO NumTools-1 DO
ReadString (pf, tools[i].title);
ReadString (pf, tools[i].command);
ReadString (pf, tools[i].arguments);
ReadBool (pf, tools[i].isActive);
ReadBool (pf, tools[i].hasConsole);
ReadString (pf, tools[i].console);
ReadBytes (pf, tools[i].stack, 4)
END;
FOR i := 0 TO NumFiles-1 DO
ReadString (pf, extensions[i])
END;
ELSE
isu.DoNotice
( NIL, SYS.ADR (Notice), "Invalid version # for preferences" )
END
ELSE
isu.DoNotice
( NIL, SYS.ADR (Notice), "Not a preferences file" )
END;
d.OldClose (pf);
ELSE
isu.DoNotice
( NIL, SYS.ADR (Notice), "Could not open setup file for load" )
END;
END LoadSetup;
(*------------------------------------*)
PROCEDURE LoadDefSetup * (defSetup : BOOLEAN);
VAR
searchPaths : ARRAY 4 OF e.LSTRPTR; baseName : e.LSTRPTR;
fileName : FileName; path : Path;
BEGIN (* LoadDefSetup *)
searchPaths [0] := SYS.ADR ("S/");
searchPaths [1] := SYS.ADR ("FPE:S/");
searchPaths [2] := SYS.ADR ("S:");
searchPaths [3] := NIL;
IF defSetup THEN fileName := "Default.fpe"
ELSE fileName := "Alternate.fpe"
END;
IF du.Search (searchPaths, fileName, path) THEN
IF defSetup THEN COPY (path, DefSetupPath)
ELSE COPY (path, AltSetupPath)
END;
LoadSetup ("", path);
ELSE
LoadSetup ("", fileName);
END;
END LoadDefSetup;
(*------------------------------------*)
PROCEDURE SaveSetup * ( setupDir, setupFile : ARRAY OF CHAR );
VAR
setupPath : Path; pf : d.FileHandlePtr;
tag : LONGINT; i : INTEGER; ver : CHAR;
PROCEDURE Write ( fh : d.FileHandlePtr; x : SYS.BYTE );
VAR i : LONGINT;
BEGIN (* Write *)
i := d.FPutC (fh, ORD (x))
END Write;
PROCEDURE WriteBytes
( fh : d.FileHandlePtr; VAR x : ARRAY OF SYS.BYTE; n : LONGINT );
VAR i : LONGINT;
BEGIN (* WriteBytes *)
i := d.FWrite (fh, x, 1, n)
END WriteBytes;
PROCEDURE WriteString ( fh : d.FileHandlePtr; x : ARRAY OF CHAR );
<*$CopyArrays-*>
BEGIN (* WriteString *)
WriteBytes (fh, x, str.Length (x)); Write (fh, 0X)
END WriteString;
PROCEDURE WriteBool ( fh : d.FileHandlePtr; x : BOOLEAN );
VAR i : SHORTINT;
BEGIN (* WriteBool *)
IF x THEN i := 1 ELSE i := 0 END; Write (fh, i)
END WriteBool;
<*$CopyArrays-*>
BEGIN (* SaveSetup *)
COPY (setupDir, setupPath);
ASSERT (d.AddPart (setupPath, setupFile, PathChars));
pf := d.Open (setupPath, d.newFile);
IF pf # NIL THEN
tag := FPEPF; WriteBytes (pf, tag, 4);
Write (pf, CHR (PrefsVersion));
FOR i := 0 TO NumTools-1 DO
WriteString (pf, tools[i].title);
WriteString (pf, tools[i].command);
WriteString (pf, tools[i].arguments);
WriteBool (pf, tools[i].isActive);
WriteBool (pf, tools[i].hasConsole);
WriteString (pf, tools[i].console);
WriteBytes (pf, tools[i].stack, 4)
END;
FOR i := 0 TO NumFiles-1 DO
WriteString (pf, extensions[i])
END;
d.OldClose (pf);
ELSE
isu.DoNotice
(NIL, SYS.ADR (Notice), "Could not open setup file for save")
END
END SaveSetup;
(*------------------------------------*)
PROCEDURE SaveDefSetup * (defSetup : BOOLEAN);
BEGIN (* SaveDefSetup *)
IF defSetup THEN
SaveSetup ("", DefSetupPath);
ELSE
SaveSetup ("", AltSetupPath)
END
END SaveDefSetup;
(*------------------------------------*)
PROCEDURE DoTool * ( which : INTEGER );
CONST
NoInput = "Failed to open input for tool";
NoOutput = "Failed to open output for tool";
LoadError = "Error loading tool";
VAR
tempCommand, tempArgs : Path;
console : Console;
result : LONGINT;
PROCEDURE Expand
( VAR newString : ARRAY OF CHAR; oldString : ARRAY OF CHAR );
VAR oldIndex, newIndex, file : INTEGER;
<*$CopyArrays-*>
BEGIN (* Expand *)
oldIndex := 0;
newIndex := 0;
newString [0] := 0X;
LOOP
IF
(newIndex >= (LEN(newString) - 1)) OR (oldString [oldIndex] = 0X)
THEN
newString [newIndex] := 0X; EXIT
END; (* IF *)
IF oldString [oldIndex] = "!" THEN
INC( oldIndex );
CASE oldString [oldIndex] OF
"D" :
newString [newIndex] := 0X;
str.Append (currentPath, newString);
newIndex := str.Length (newString);
|
"F" :
newString [newIndex] := 0X;
file := 0;
WHILE file < NumFiles DO
IF file IN currentFiles THEN
str.Append (currentModule.modName, newString);
str.Append (".", newString);
str.Append (extensions [file], newString);
str.Append (" ", newString);
END; (* IF *)
INC (file)
END; (* WHILE *)
newIndex := str.Length (newString);
|
"M" :
newString [newIndex] := 0X;
str.Append (currentModule.modName, newString);
newIndex := str.Length (newString);
|
"P" :
newString [newIndex] := 0X;
str.Append (programName, newString);
newIndex := str.Length (newString);
|
ELSE
newString [newIndex] := oldString [oldIndex];
INC( newIndex );
END; (* CASE oldString *)
INC( oldIndex );
ELSE
newString [newIndex] := oldString [oldIndex];
INC( oldIndex ); INC( newIndex )
END;
END; (* LOOP *)
END Expand;
(*------------------------------------*)
PROCEDURE DosCall ();
VAR file : d.FileHandlePtr;
BEGIN (* DosCall *)
IF tools [which].hasConsole THEN
file := d.Open (console, d.oldFile);
IF file = NIL THEN
isu.DoNotice (NIL, SYS.ADR (Notice), "Could not open console");
RETURN
END
ELSE
file := NIL
END;
str.Append (" ", tempCommand);
str.Append (tempArgs, tempCommand);
IF
d.SystemTags
( tempCommand,
d.sysInput, file,
d.sysOutput, NIL,
d.sysAsynch, d.DOSTRUE,
d.npStackSize, tools [which].stack,
u.done )
= -1
THEN
IF file # NIL THEN d.OldClose (file) END;
isu.DoNotice (NIL, SYS.ADR (Notice), LoadError)
END;
END DosCall;
BEGIN (* DoTool *)
Expand (tempCommand, tools [which].command);
Expand (tempArgs, tools [which].arguments);
IF tools [which].hasConsole THEN
Expand (console, tools [which].console);
END;
DosCall ()
END DoTool;
(*------------------------------------*)
PROCEDURE Init * ();
BEGIN (* Init *)
tools [0].title := "Button0";
tools [1].title := "Button1";
tools [2].title := "Button2";
tools [3].title := "Button3";
tools [4].title := "Button4";
tools [5].title := "Button5";
tools [6].title := "Button6";
tools [7].title := "Button7";
tools [8].title := "Button8";
tools [9].title := "Button9";
tools [10].title := "Button10";
tools [11].title := "Button11";
extensions [0] := "ex0";
extensions [1] := "ex1";
extensions [2] := "ex2";
extensions [3] := "ex3";
es.NewList (moduleList);
LoadDefSetup (TRUE);
END Init;
BEGIN
DefSetupPath := "FPE:S/Default.fpe"; AltSetupPath := "FPE:S/Alternate.fpe"
END Data.
(***************************************************************************
$Log: Data.mod $
Revision 1.12 1995/05/08 16:41:15 fjc
- Removed inappropriate SHORT() calls.
Revision 1.11 1995/02/07 20:12:32 fjc
- Release 1.5 update 1
Revision 1.10 1995/01/26 00:15:33 fjc
- Release 1.5
Revision 1.9 1994/09/25 18:20:54 fjc
- Uses new syntax for external code declarations
Revision 1.8 1994/08/08 16:13:09 fjc
Release 1.4
Revision 1.7 1994/06/21 22:03:49 fjc
- Added code to conditionally use V37+ dos.library instead
of arp.library.
Revision 1.6 1994/06/17 17:26:27 fjc
- Updated for release
Revision 1.5 1994/06/09 13:33:46 fjc
- Incorporated changes in Amiga interface
Revision 1.4 1994/06/04 23:49:52 fjc
- Changed to use new Amiga interface
Revision 1.3 1994/05/12 21:26:09 fjc
- Prepared for release
Revision 1.2 1994/01/24 14:33:33 fjc
Changed version control header
Revision 1.1 1994/01/15 17:32:38 fjc
Start of revision control
***************************************************************************)